package com.doubledragon.tiny.context;

import com.doubledragon.tiny.ioc.factory.AbstractBeanFactory;

/**
 * Created by dragon
 *
 * 抽象的ApplicationContext， 关键在于refresh方法，它几乎包含了ApplicationContext中的全部功能，
 */
public abstract class AbstractApplicationContext implements ApplicationContext {

    protected AbstractBeanFactory beanFactory;

    public AbstractApplicationContext(AbstractBeanFactory beanFactory){
        this.beanFactory = beanFactory;
    }

    @Override
    public Object getBean(String beanName) throws Exception {
        return this.beanFactory.getBean(beanName);
    }

    // 对BeanFactory进行扩展的操作都在这里面,
    // 包括初始化BeanFactory，解析xml文件等BeanFactory需要实现的功能
    // 和其他的扩展功能，如对BeanFactory功能的填充，激活各种BeanFactory处理器，注册bean处理器(BeanPostProcesser)等
    public void refresh() throws Exception {
        this.loadBeanDefinition();
        this.registryBeanPostProccesser();
    }

    protected abstract void registryBeanPostProccesser() throws Exception;

    public abstract void loadBeanDefinition() throws Exception;

}
